package Tests;

import org.jrabbit.base.sound.Music;
import org.jrabbit.standard.game.graphics.skins.image.ImageSkin;
import org.jrabbit.standard.game.main.StandardGame;
import org.jrabbit.standard.game.objects.base.BaseSprite;
import org.lwjgl.opengl.GL11;

import Code.Basic.Structures.Wall;
import Code.Basic.World.GameWorld;
import Code.Objects.Characters.Player.Player;

public class DeadSteelTest2 extends StandardGame
{
	public DeadSteelTest2()
	{
		super("Dead Steel", "Resources/Images/General/Icon.png");
	}
	
	protected void setup()
	{
		GameWorld gW = new GameWorld();
		gW.addPlayer(new Player());
		gW.makeCurrent();
		gW.initialize();

		Music.loop("Resources/Sounds/Music/Again We Stand.ogg");
		profiler.createNewTracker("Physics");
		
		Wall testWall1 = new Wall("Resources/Images/Terrain/Interiors/Walls/Simple Steel Wall 1.png", 1280);
		testWall1.setLocation(0, -640);
		testWall1.setRotation(0);
		gW.addObstacle(testWall1, "Structures");
		
		Wall testWall2 = new Wall("Resources/Images/Terrain/Interiors/Walls/Simple Steel Wall 1.png", 1280);
		testWall2.setLocation(640, 0);
		testWall2.setRotation(90);
		gW.addObstacle(testWall2, "Structures");
		
		Wall testWall3 = new Wall("Resources/Images/Terrain/Interiors/Walls/Simple Steel Wall 1.png", 1280);
		testWall3.setLocation(0, 640);
		testWall3.setRotation(180);
		gW.addObstacle(testWall3, "Structures");
		
		Wall testWall4 = new Wall("Resources/Images/Terrain/Interiors/Walls/Simple Steel Wall 1.png", 1280);
		testWall4.setLocation(-640, 0);
		testWall4.setRotation(270);
		gW.addObstacle(testWall4, "Structures");
		
		gW.addRenderable(new MetalTiles(20, 20), "Terrain");
	}
	
	private class MetalTiles extends BaseSprite
	{
		ImageSkin tile;
		
		private int w;
		private int h;
		
		public MetalTiles(int width, int height)
		{
			super();
			tile = new ImageSkin("Resources/Images/Terrain/Interiors/Flooring/Metal Grate 2.png");
			w = width;
			h = height;
		}
		
		public double getWidth()
		{
			return tile.width() * w;
		}
		
		public double getHeight()
		{
			return tile.height() * h;
		}
		
		public void draw()
		{
			GL11.glBegin(GL11.GL_QUADS);			
			
				float width = (float) (getWidth() / 2);
				float height = (float) (getHeight() / 2);
				
				GL11.glTexCoord2f(0, 0);
				GL11.glVertex2f(-width, -height);
				
				GL11.glTexCoord2f(w, 0);
				GL11.glVertex2f(width, -height);
				
				GL11.glTexCoord2f(w, h);
				GL11.glVertex2f(width, height);
				
				GL11.glTexCoord2f(0, h);
				GL11.glVertex2f(-width, height);
			
			GL11.glEnd();
		}
	}
	
	public static void main(String[] args)
	{
		init();
		new DeadSteelTest2().run();
	}
}